/*
 * @lc app=leetcode.cn id=520 lang=cpp
 *
 * [520] 检测大写字母
 */

// @lc code=start
class Solution
{
public:
  bool detectCapitalUse(string s)
  {
    if (s[0] >= 97 && s[0] <= 122) // lower
      return CheckLower(s, 1, s.size());
    else // upper
      return CheckLower(s, 1, s.size()) || CheckUpper(s, 1, s.size());
  }

  // 97~122
  bool CheckLower(const string& s, int begin, int end)
  {
    for (; begin < end; ++begin) {
      char c = s[begin];
      if (c >= 65 && c <= 90)
        return false;
    }
    return true;
  }

  // 65~90
  bool CheckUpper(const string& s, int begin, int end)
  {
    for (; begin < end; ++begin) {
      char c = s[begin];
      if (c >= 97 && c <= 122)
        return false;
    }
    return true;
  }
};
// @lc code=end
